package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yinsh
 * Date: 2025-01-13
 * Time: 20:52
 */
public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入要删除的书名》");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();
        boolean flag = false;
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if (name.equals(bookList.books[i].getName())) {
                bookList.books[i] = bookList.books[i + 1];
                bookList.setUsedSize(bookList.getUsedSize() - 1);
                flag = true;
            }
        }
        if (!flag) {
            System.out.println("此书不存在");
        }
    }
}
